package sg.edu.nus.iss.jass.persistence;

import java.util.List;

import sg.edu.nus.iss.jass.datastore.BaseDAO;
import sg.edu.nus.iss.jass.datastore.exception.DataStoreException;
import sg.edu.nus.iss.jass.datastore.impl.Selector;
import sg.edu.nus.iss.jass.dto.JobSeeker;
import sg.edu.nus.iss.jass.util.Util;

/**
 * <h5>JobSeekerDAO to perform jobseeker data operation</h5>
 * This  abstract class is derived from BaseDAO to get/save the jobseeker object.
 * @author Iwan Sinardinata
 * 
 */
public class JobSeekerDAO extends BaseDAO {

	/**
	 *  Method to get jobseeker id
	 * @param userID
	 *            String userID.
	 */	
	public JobSeeker getJobSeekerByID(String userID) throws DataStoreException {
		//return selectById(JobSeeker.class, id);
		List<JobSeeker> jobSeekerList = null;
		JobSeeker jobSeekerObj = null;
		try {
			jobSeekerList = select(JobSeeker.class, (new Selector()).eq("userId", userID.toLowerCase()));
		} catch(DataStoreException e) {
			//e.printStackTrace();
			//throw new ControllerException(ErrorCodeConstants.ERROR_DATASTORE, MessageKeyManager.getMessage("error.dataStore"));
		}
		if (!Util.isEmpty(jobSeekerList)) {
			jobSeekerObj = jobSeekerList.get(0);
		}
		return jobSeekerObj;
	}

	/**
	 *  Method to insert jobseeker records.
	 * @param jobSeeker
	 *            JobSeeker jobSeeker object.
	 */	
	public void addJobSeeker(JobSeeker jobSeeker) throws DataStoreException {
		save(jobSeeker);
	}

}
